package com.example.administrator.tenyuanpackage.speacial;


import android.content.Context;
import android.graphics.Color;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.design.widget.TabLayout;
import android.support.v4.app.Fragment;
import android.support.v4.view.ViewPager;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.example.administrator.tenyuanpackage.R;
import com.example.administrator.tenyuanpackage.speacial.adapter.TenViewPagerAdapter;
import com.example.administrator.tenyuanpackage.speacial.fragment.TenFragment;

import java.util.ArrayList;


public class TenBuyFragment extends Fragment {

    private Context mContext=getContext();
    private TabLayout tb_ten;
    private ViewPager vp_ten;

    public TenBuyFragment() {

    }


    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {

        return inflater.inflate(R.layout.fragment_ten_buy, container, false);
    }

    @Override
    public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
        super.onViewCreated(view, savedInstanceState);

        tb_ten = (TabLayout) view.findViewById(R.id.tb_ten);
        vp_ten = (ViewPager) view.findViewById(R.id.vp_ten);
        String [] ten_Titles={"精选","10元","20元","30元"};

        ArrayList<Fragment> fragments=new ArrayList<>();
        for (int i = 0; i < ten_Titles.length; i++) {
            fragments.add(TenFragment.getInsatance_ten(i));
        }

        tb_ten.setTabTextColors(Color.BLACK,Color.RED);
        tb_ten.setTabMode(TabLayout.MODE_SCROLLABLE);
        tb_ten.setSelectedTabIndicatorColor(Color.RED);
        tb_ten.setTabMode(TabLayout.MODE_FIXED);
        //界面之间来回切换都不会重新加载
        vp_ten.setOffscreenPageLimit(fragments.size());



        vp_ten.setAdapter(new TenViewPagerAdapter(getFragmentManager(),mContext,fragments,ten_Titles));

        tb_ten.setupWithViewPager(vp_ten);
    }
}
